home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-PPC / PGTABLE.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  22KB  |  643 lines

  1. #include <linux/config.h>
  2.  
  3. #ifndef _PPC_PGTABLE_H
  4. #define _PPC_PGTABLE_H
  5.  
  6. #ifndef __ASSEMBLY__
  7. #include <linux/mm.h>
  8. #include <asm/processor.h>        /* For TASK_SIZE */
  9. #include <asm/mmu.h>
  10. #include <asm/page.h>
  11.  
  12. extern void local_flush_tlb_all(void);
  13. extern void local_flush_tlb_mm(struct mm_struct *mm);
  14. extern void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
  15. extern void local_flush_tlb_range(struct mm_struct *mm, unsigned long start,
  16.                 unsigned long end);
  17.  
  18. #define flush_tlb_all local_flush_tlb_all
  19. #define flush_tlb_mm local_flush_tlb_mm
  20. #define flush_tlb_page local_flush_tlb_page
  21. #define flush_tlb_range local_flush_tlb_range
  22.  
  23. /*
  24.  * No cache flushing is required when address mappings are
  25.  * changed, because the caches on PowerPCs are physically
  26.  * addressed.
  27.  * Also, when SMP we use the coherency (M) bit of the
  28.  * BATs and PTEs.  -- Cort
  29.  */
  30. #define flush_cache_all()        do { } while (0)
  31. #define flush_cache_mm(mm)        do { } while (0)
  32. #define flush_cache_range(mm, a, b)    do { } while (0)
  33. #define flush_cache_page(vma, p)    do { } while (0)
  34.  
  35. extern void flush_icache_range(unsigned long, unsigned long);
  36. extern void flush_page_to_ram(unsigned long);
  37.  
  38. extern unsigned long va_to_phys(unsigned long address);
  39. extern pte_t *va_to_pte(struct task_struct *tsk, unsigned long address);
  40. #endif /* __ASSEMBLY__ */
  41. /*
  42.  * The PowerPC MMU uses a hash table containing PTEs, together with
  43.  * a set of 16 segment registers (on 32-bit implementations), to define
  44.  * the virtual to physical address mapping.
  45.  *
  46.  * We use the hash table as an extended TLB, i.e. a cache of currently
  47.  * active mappings.  We maintain a two-level page table tree, much like
  48.  * that used by the i386, for the sake of the Linux memory management code.
  49.  * Low-level assembler code in head.S (procedure hash_page) is responsible
  50.  * for extracting ptes from the tree and putting them into the hash table
  51.  * when necessary, and updating the accessed and modified bits in the
  52.  * page table tree.
  53.  *
  54.  * The PowerPC MPC8xx uses a TLB with hardware assisted, software tablewalk.
  55.  * We also use the two level tables, but we can put the real bits in them
  56.  * needed for the TLB and tablewalk.  These definitions require Mx_CTR.PPM = 0,
  57.  * Mx_CTR.PPCS = 0, and MD_CTR.TWAM = 1.  The level 2 descriptor has
  58.  * additional page protection (when Mx_CTR.PPCS = 1) that allows TLB hit
  59.  * based upon user/super access.  The TLB does not have accessed nor write
  60.  * protect.  We assume that if the TLB get loaded with an entry it is
  61.  * accessed, and overload the changed bit for write protect.  We use
  62.  * two bits in the software pte that are supposed to be set to zero in
  63.  * the TLB entry (24 and 25) for these indicators.  Although the level 1
  64.  * descriptor contains the guarded and writethrough/copyback bits, we can
  65.  * set these at the page level since they get copied from the Mx_TWC
  66.  * register when the TLB entry is loaded.  We will use bit 27 for guard, since
  67.  * that is where it exists in the MD_TWC, and bit 26 for writethrough.
  68.  * These will get masked from the level 2 descriptor at TLB load time, and
  69.  * copied to the MD_TWC before it gets loaded.
  70.  */
  71.  
  72. /* PMD_SHIFT determines the size of the area mapped by the second-level page tables */
  73. #define PMD_SHIFT    22
  74. #define PMD_SIZE    (1UL << PMD_SHIFT)
  75. #define PMD_MASK    (~(PMD_SIZE-1))
  76.  
  77. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  78. #define PGDIR_SHIFT    22
  79. #define PGDIR_SIZE    (1UL << PGDIR_SHIFT)
  80. #define PGDIR_MASK    (~(PGDIR_SIZE-1))
  81.  
  82. /*
  83.  * entries per page directory level: our page-table tree is two-level, so
  84.  * we don't really have any PMD directory.
  85.  */
  86. #define PTRS_PER_PTE    1024
  87. #define PTRS_PER_PMD    1
  88. #define PTRS_PER_PGD    1024
  89. #define USER_PTRS_PER_PGD    (TASK_SIZE / PGDIR_SIZE)
  90.  
  91. /* Just any arbitrary offset to the start of the vmalloc VM area: the
  92.  * current 64MB value just means that there will be a 64MB "hole" after the
  93.  * physical memory until the kernel virtual memory starts.  That means that
  94.  * any out-of-bounds memory accesses will hopefully be caught.
  95.  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  96.  * area for the same reason. ;)
  97.  *
  98.  * The vmalloc_offset MUST be larger than the gap between the bat2 mapping
  99.  * and the size of physical ram.  Since the bat2 mapping can be larger than
  100.  * the amount of ram we have vmalloc_offset must ensure that we don't try
  101.  * to allocate areas that don't exist! This value of 64M will only cause
  102.  * problems when we have >128M -- Cort
  103.  */
  104. #define VMALLOC_OFFSET    (0x4000000) /* 64M */
  105. #define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
  106. #define VMALLOC_VMADDR(x) ((unsigned long)(x))
  107. #define VMALLOC_END    0xf0000000
  108.  
  109. /*
  110.  * Bits in a linux-style PTE.  These match the bits in the
  111.  * (hardware-defined) PowerPC PTE as closely as possible.
  112.  */
  113. #ifndef CONFIG_8xx
  114. #define _PAGE_PRESENT    0x001    /* software: pte contains a translation */
  115. #define _PAGE_USER    0x002    /* matches one of the PP bits */
  116. #define _PAGE_RW    0x004    /* software: user write access allowed */
  117. #define _PAGE_GUARDED    0x008
  118. #define _PAGE_COHERENT    0x010    /* M: enforce memory coherence (SMP systems) */
  119. #define _PAGE_NO_CACHE    0x020    /* I: cache inhibit */
  120. #define _PAGE_WRITETHRU    0x040    /* W: cache write-through */
  121. #define _PAGE_DIRTY    0x080    /* C: page changed */
  122. #define _PAGE_ACCESSED    0x100    /* R: page referenced */
  123. #define _PAGE_HWWRITE    0x200    /* software: _PAGE_RW & _PAGE_DIRTY */
  124. #define _PAGE_SHARED    0
  125.  
  126. #else
  127. #define _PAGE_PRESENT    0x0001    /* Page is valid */
  128. #define _PAGE_NO_CACHE    0x0002    /* I: cache inhibit */
  129. #define _PAGE_SHARED    0x0004    /* No ASID (context) compare */
  130.  
  131. /* These four software bits must be masked out when the entry is loaded
  132.  * into the TLB.
  133.  */
  134. #define _PAGE_GUARDED    0x0010    /* software: guarded access */
  135. #define _PAGE_WRITETHRU 0x0020    /* software: use writethrough cache */
  136. #define _PAGE_RW    0x0040    /* software: user write access allowed */
  137. #define _PAGE_ACCESSED    0x0080    /* software: page referenced */
  138.  
  139. #define _PAGE_DIRTY    0x0100    /* C: page changed (write protect) */
  140. #define _PAGE_USER    0x0800    /* One of the PP bits, the other must be 0 */
  141.  
  142. /* This is used to enable or disable the actual hardware write
  143.  * protection.
  144.  */
  145. #define _PAGE_HWWRITE    _PAGE_DIRTY
  146.  
  147. #endif /* CONFIG_8xx */
  148.  
  149. #define _PAGE_CHG_MASK    (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  150.  
  151. #ifdef __SMP__
  152. #define _PAGE_BASE    _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT
  153. #else
  154. #define _PAGE_BASE    _PAGE_PRESENT | _PAGE_ACCESSED
  155. #endif
  156. #define _PAGE_WRENABLE    _PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE
  157.  
  158. #define PAGE_NONE    __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
  159.  
  160. #define PAGE_SHARED    __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | \
  161.                  _PAGE_SHARED)
  162. #define PAGE_COPY    __pgprot(_PAGE_BASE | _PAGE_USER)
  163. #define PAGE_READONLY    __pgprot(_PAGE_BASE | _PAGE_USER)
  164. #define PAGE_KERNEL    __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED)
  165. #define PAGE_KERNEL_CI    __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | \
  166.                  _PAGE_NO_CACHE )
  167.  
  168. /*
  169.  * The PowerPC can only do execute protection on a segment (256MB) basis,
  170.  * not on a page basis.  So we consider execute permission the same as read.
  171.  * Also, write permissions imply read permissions.
  172.  * This is the closest we can get..
  173.  */
  174. #define __P000    PAGE_NONE
  175. #define __P001    PAGE_READONLY
  176. #define __P010    PAGE_COPY
  177. #define __P011    PAGE_COPY
  178. #define __P100    PAGE_READONLY
  179. #define __P101    PAGE_READONLY
  180. #define __P110    PAGE_COPY
  181. #define __P111    PAGE_COPY
  182.  
  183. #define __S000    PAGE_NONE
  184. #define __S001    PAGE_READONLY
  185. #define __S010    PAGE_SHARED
  186. #define __S011    PAGE_SHARED
  187. #define __S100    PAGE_READONLY
  188. #define __S101    PAGE_READONLY
  189. #define __S110    PAGE_SHARED
  190. #define __S111    PAGE_SHARED
  191.  
  192. /*
  193.  * BAD_PAGETABLE is used when we need a bogus page-table, while
  194.  * BAD_PAGE is used for a bogus page.
  195.  *
  196.  * ZERO_PAGE is a global shared page that is always zero: used
  197.  * for zero-mapped memory areas etc..
  198.  */
  199. #ifndef __ASSEMBLY__
  200. extern pte_t __bad_page(void);
  201. extern pte_t * __bad_pagetable(void);
  202.  
  203. extern unsigned long empty_zero_page[1024];
  204. #endif __ASSEMBLY__
  205. #define BAD_PAGETABLE    __bad_pagetable()
  206. #define BAD_PAGE    __bad_page()
  207. #define ZERO_PAGE    ((unsigned long) empty_zero_page)
  208.  
  209. /* number of bits that fit into a memory pointer */
  210. #define BITS_PER_PTR    (8*sizeof(unsigned long))
  211.  
  212. /* to align the pointer to a pointer address */
  213. #define PTR_MASK    (~(sizeof(void*)-1))
  214.  
  215. /* sizeof(void*) == 1<<SIZEOF_PTR_LOG2 */
  216. /* 64-bit machines, beware!  SRB. */
  217. #define SIZEOF_PTR_LOG2    2
  218.  
  219. /* to set the page-dir */
  220. /* tsk is a task_struct and pgdir is a pte_t */
  221. #ifndef CONFIG_8xx
  222. #define SET_PAGE_DIR(tsk,pgdir)  \
  223.     ((tsk)->tss.pg_tables = (unsigned long *)(pgdir))
  224. #else /* CONFIG_8xx */     
  225. #define SET_PAGE_DIR(tsk,pgdir)  \
  226.  do { \
  227.     unsigned long __pgdir = (unsigned long)pgdir; \
  228.     ((tsk)->tss.pg_tables = (unsigned long *)(__pgdir)); \
  229.     asm("mtspr %0,%1 \n\t" : : "i"(M_TWB), "r"(__pa(__pgdir))); \
  230.  } while (0)
  231. #endif /* CONFIG_8xx */
  232.      
  233. #ifndef __ASSEMBLY__
  234. extern inline int pte_none(pte_t pte)        { return !pte_val(pte); }
  235. extern inline int pte_present(pte_t pte)    { return pte_val(pte) & _PAGE_PRESENT; }
  236. extern inline void pte_clear(pte_t *ptep)    { pte_val(*ptep) = 0; }
  237.  
  238. extern inline int pmd_none(pmd_t pmd)        { return !pmd_val(pmd); }
  239. extern inline int pmd_bad(pmd_t pmd)        { return (pmd_val(pmd) & ~PAGE_MASK) != 0; }
  240. extern inline int pmd_present(pmd_t pmd)    { return (pmd_val(pmd) & PAGE_MASK) != 0; }
  241. extern inline void pmd_clear(pmd_t * pmdp)    { pmd_val(*pmdp) = 0; }
  242.  
  243.  
  244. /*
  245.  * The "pgd_xxx()" functions here are trivial for a folded two-level
  246.  * setup: the pgd is never bad, and a pmd always exists (as it's folded
  247.  * into the pgd entry)
  248.  */
  249. extern inline int pgd_none(pgd_t pgd)        { return 0; }
  250. extern inline int pgd_bad(pgd_t pgd)        { return 0; }
  251. extern inline int pgd_present(pgd_t pgd)    { return 1; }
  252. extern inline void pgd_clear(pgd_t * pgdp)    { }
  253.  
  254. /*
  255.  * The following only work if pte_present() is true.
  256.  * Undefined behaviour if not..
  257.  */
  258. extern inline int pte_read(pte_t pte)        { return pte_val(pte) & _PAGE_USER; }
  259. extern inline int pte_write(pte_t pte)        { return pte_val(pte) & _PAGE_RW; }
  260. extern inline int pte_exec(pte_t pte)        { return pte_val(pte) & _PAGE_USER; }
  261. extern inline int pte_dirty(pte_t pte)        { return pte_val(pte) & _PAGE_DIRTY; }
  262. extern inline int pte_young(pte_t pte)        { return pte_val(pte) & _PAGE_ACCESSED; }
  263.  
  264. extern inline void pte_uncache(pte_t pte)       { pte_val(pte) |= _PAGE_NO_CACHE; }
  265. extern inline void pte_cache(pte_t pte)         { pte_val(pte) &= ~_PAGE_NO_CACHE; }
  266.  
  267. extern inline pte_t pte_rdprotect(pte_t pte) {
  268.     pte_val(pte) &= ~_PAGE_USER; return pte; }
  269. extern inline pte_t pte_exprotect(pte_t pte) {
  270.     pte_val(pte) &= ~_PAGE_USER; return pte; }
  271. extern inline pte_t pte_wrprotect(pte_t pte) {
  272.     pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
  273. extern inline pte_t pte_mkclean(pte_t pte) {
  274.     pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  275. extern inline pte_t pte_mkold(pte_t pte) {
  276.     pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  277.  
  278. extern inline pte_t pte_mkread(pte_t pte) {
  279.     pte_val(pte) |= _PAGE_USER; return pte; }
  280. extern inline pte_t pte_mkexec(pte_t pte) {
  281.     pte_val(pte) |= _PAGE_USER; return pte; }
  282. extern inline pte_t pte_mkwrite(pte_t pte)
  283. {
  284.     pte_val(pte) |= _PAGE_RW;
  285.     if (pte_val(pte) & _PAGE_DIRTY)
  286.         pte_val(pte) |= _PAGE_HWWRITE;
  287.     return pte;
  288. }
  289. extern inline pte_t pte_mkdirty(pte_t pte)
  290. {
  291.     pte_val(pte) |= _PAGE_DIRTY;
  292.     if (pte_val(pte) & _PAGE_RW)
  293.         pte_val(pte) |= _PAGE_HWWRITE;
  294.     return pte;
  295. }
  296. extern inline pte_t pte_mkyoung(pte_t pte) {
  297.     pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  298.  
  299. /* Certain architectures need to do special things when pte's
  300.  * within a page table are directly modified.  Thus, the following
  301.  * hook is made available.
  302.  */
  303. #if 1
  304. #define set_pte(pteptr, pteval)    ((*(pteptr)) = (pteval))
  305. #else
  306. extern inline void set_pte(pte_t *pteptr, pte_t pteval)
  307. {
  308.     unsigned long val = pte_val(pteval);
  309.     extern void xmon(void *);
  310.  
  311.     if ((val & _PAGE_PRESENT) && ((val < 0x111000 || (val & 0x800)
  312.         || ((val & _PAGE_HWWRITE) && (~val & (_PAGE_RW|_PAGE_DIRTY)))) {
  313.         printk("bad pte val %lx ptr=%p\n", val, pteptr);
  314.         xmon(0);
  315.     }
  316.     *pteptr = pteval;
  317. }
  318. #endif
  319.  
  320. /*
  321.  * Conversion functions: convert a page and protection to a page entry,
  322.  * and a page entry and page directory to the page they refer to.
  323.  */
  324.  
  325. static inline pte_t mk_pte_phys(unsigned long page, pgprot_t pgprot)
  326. { pte_t pte; pte_val(pte) = (page) | pgprot_val(pgprot); return pte; }
  327.  
  328. extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
  329. { pte_t pte; pte_val(pte) = __pa(page) | pgprot_val(pgprot); return pte; }
  330.  
  331. extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  332. { pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
  333.  
  334. extern inline unsigned long pte_page(pte_t pte)
  335. { return (unsigned long) __va(pte_val(pte) & PAGE_MASK); }
  336.  
  337. extern inline unsigned long pmd_page(pmd_t pmd)
  338. { return pmd_val(pmd); }
  339.  
  340.  
  341. /* to find an entry in a kernel page-table-directory */
  342. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  343.  
  344. /* to find an entry in a page-table-directory */
  345. extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
  346. {
  347.     return mm->pgd + (address >> PGDIR_SHIFT);
  348. }
  349.  
  350. /* Find an entry in the second-level page table.. */
  351. extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
  352. {
  353.     return (pmd_t *) dir;
  354. }
  355.  
  356. /* Find an entry in the third-level page table.. */ 
  357. extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
  358. {
  359.     return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
  360. }
  361.  
  362. /*
  363.  * This is handled very differently on the PPC since out page tables
  364.  * are all 0's and I want to be able to use these zero'd pages elsewhere
  365.  * as well - it gives us quite a speedup.
  366.  *
  367.  * Note that the SMP/UP versions are the same but we don't need a
  368.  * per cpu list of zero pages because we do the zero-ing with the cache
  369.  * off and the access routines are lock-free but the pgt cache stuff
  370.  * is per-cpu since it isn't done with any lock-free access routines
  371.  * (although I think we need arch-specific routines so I can do lock-free).
  372.  *
  373.  * I need to generalize this so we can use it for other arch's as well.
  374.  * -- Cort
  375.  */
  376. #ifdef __SMP__
  377. #define quicklists    cpu_data[smp_processor_id()]
  378. #else
  379. extern struct pgtable_cache_struct {
  380.     unsigned long *pgd_cache;
  381.     unsigned long *pte_cache;
  382.     unsigned long pgtable_cache_sz;
  383. } quicklists;
  384. #endif
  385.  
  386. #define pgd_quicklist         (quicklists.pgd_cache)
  387. #define pmd_quicklist         ((unsigned long *)0)
  388. #define pte_quicklist         (quicklists.pte_cache)
  389. #define pgtable_cache_size     (quicklists.pgtable_cache_sz)
  390.  
  391. extern unsigned long *zero_cache;    /* head linked list of pre-zero'd pages */
  392. extern unsigned long zero_sz;         /* # currently pre-zero'd pages */
  393. extern unsigned long zeropage_hits;  /* # zero'd pages request that we've done */
  394. extern unsigned long zeropage_calls; /* # zero'd pages request that've been made */
  395. extern unsigned long zerototal;      /* # pages zero'd over time */
  396.  
  397. #define zero_quicklist         (zero_cache)
  398. #define zero_cache_sz           (zero_sz)
  399. #define zero_cache_calls     (zeropage_calls)
  400. #define zero_cache_hits      (zeropage_hits)
  401. #define zero_cache_total     (zerototal)
  402.  
  403. /* return a pre-zero'd page from the list, return NULL if none available -- Cort */
  404. extern unsigned long get_zero_page_fast(void);
  405.  
  406. extern __inline__ pgd_t *get_pgd_slow(void)
  407. {
  408.     pgd_t *ret/* = (pgd_t *)__get_free_page(GFP_KERNEL)*/, *init;
  409.  
  410.     if ( (ret = (pgd_t *)get_zero_page_fast()) == NULL )
  411.     {
  412.         if ( (ret = (pgd_t *)__get_free_page(GFP_KERNEL)) != NULL )
  413.             memset (ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  414.     }
  415.     if (ret) {
  416.         init = pgd_offset(&init_mm, 0);
  417.         /*memset (ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));*/
  418.         memcpy (ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  419.             (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  420.     }
  421.     return ret;
  422. }
  423.  
  424. extern __inline__ pgd_t *get_pgd_fast(void)
  425. {
  426.         unsigned long *ret;
  427.  
  428.         if((ret = pgd_quicklist) != NULL) {
  429.                 pgd_quicklist = (unsigned long *)(*ret);
  430.                 ret[0] = ret[1];
  431.                 pgtable_cache_size--;
  432.         } else
  433.                 ret = (unsigned long *)get_pgd_slow();
  434.         return (pgd_t *)ret;
  435. }
  436.  
  437. extern __inline__ void free_pgd_fast(pgd_t *pgd)
  438. {
  439.         *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
  440.         pgd_quicklist = (unsigned long *) pgd;
  441.         pgtable_cache_size++;
  442. }
  443.  
  444. extern __inline__ void free_pgd_slow(pgd_t *pgd)
  445. {
  446.     free_page((unsigned long)pgd);
  447. }
  448.  
  449. extern pte_t *get_pte_slow(pmd_t *pmd, unsigned long address_preadjusted);
  450.  
  451. extern __inline__ pte_t *get_pte_fast(void)
  452. {
  453.         unsigned long *ret;
  454.  
  455.         if((ret = (unsigned long *)pte_quicklist) != NULL) {
  456.                 pte_quicklist = (unsigned long *)(*ret);
  457.                 ret[0] = ret[1];
  458.                 pgtable_cache_size--;
  459.          }
  460.         return (pte_t *)ret;
  461. }
  462.  
  463. extern __inline__ void free_pte_fast(pte_t *pte)
  464. {
  465.         *(unsigned long *)pte = (unsigned long) pte_quicklist;
  466.         pte_quicklist = (unsigned long *) pte;
  467.         pgtable_cache_size++;
  468. }
  469.  
  470. extern __inline__ void free_pte_slow(pte_t *pte)
  471. {
  472.     free_page((unsigned long)pte);
  473. }
  474.  
  475. /* We don't use pmd cache, so this is a dummy routine */
  476. extern __inline__ pmd_t *get_pmd_fast(void)
  477. {
  478.     return (pmd_t *)0;
  479. }
  480.  
  481. extern __inline__ void free_pmd_fast(pmd_t *pmd)
  482. {
  483. }
  484.  
  485. extern __inline__ void free_pmd_slow(pmd_t *pmd)
  486. {
  487. }
  488.  
  489. extern void __bad_pte(pmd_t *pmd);
  490.  
  491. #define pte_free_kernel(pte)    free_pte_fast(pte)
  492. #define pte_free(pte)           free_pte_fast(pte)
  493. #define pgd_free(pgd)           free_pgd_fast(pgd)
  494. #define pgd_alloc()             get_pgd_fast()
  495.  
  496. extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
  497. {
  498.     address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
  499.     if (pmd_none(*pmd)) {
  500.         pte_t * page = (pte_t *) get_pte_fast();
  501.         
  502.         if (!page)
  503.             return get_pte_slow(pmd, address);
  504.         pmd_val(*pmd) = (unsigned long) page;
  505.         return page + address;
  506.     }
  507.     if (pmd_bad(*pmd)) {
  508.         __bad_pte(pmd);
  509.         return NULL;
  510.     }
  511.     return (pte_t *) pmd_page(*pmd) + address;
  512. }
  513.  
  514. /*
  515.  * allocating and freeing a pmd is trivial: the 1-entry pmd is
  516.  * inside the pgd, so has no extra memory associated with it.
  517.  */
  518. extern inline void pmd_free(pmd_t * pmd)
  519. {
  520. }
  521.  
  522. extern inline pmd_t * pmd_alloc(pgd_t * pgd, unsigned long address)
  523. {
  524.     return (pmd_t *) pgd;
  525. }
  526.  
  527. #define pmd_free_kernel        pmd_free
  528. #define pmd_alloc_kernel    pmd_alloc
  529. #define pte_alloc_kernel    pte_alloc
  530.  
  531. extern int do_check_pgt_cache(int, int);
  532.  
  533. extern inline void set_pgdir(unsigned long address, pgd_t entry)
  534. {
  535.     struct task_struct * p;
  536.     pgd_t *pgd;
  537. #ifdef __SMP__
  538.     int i;
  539. #endif    
  540.         
  541.     read_lock(&tasklist_lock);
  542.     for_each_task(p) {
  543.         if (!p->mm)
  544.             continue;
  545.         *pgd_offset(p->mm,address) = entry;
  546.     }
  547.     read_unlock(&tasklist_lock);
  548. #ifndef __SMP__
  549.     for (pgd = (pgd_t *)pgd_quicklist; pgd; pgd = (pgd_t *)*(unsigned long *)pgd)
  550.         pgd[address >> PGDIR_SHIFT] = entry;
  551. #else
  552.     /* To pgd_alloc/pgd_free, one holds master kernel lock and so does our callee, so we can
  553.        modify pgd caches of other CPUs as well. -jj */
  554.     for (i = 0; i < NR_CPUS; i++)
  555.         for (pgd = (pgd_t *)cpu_data[i].pgd_cache; pgd; pgd = (pgd_t *)*(unsigned long *)pgd)
  556.             pgd[address >> PGDIR_SHIFT] = entry;
  557. #endif
  558. }
  559.  
  560. extern pgd_t swapper_pg_dir[1024];
  561.  
  562. extern __inline__ pte_t *find_pte(struct mm_struct *mm,unsigned long va)
  563. {
  564.     pgd_t *dir;
  565.     pmd_t *pmd;
  566.     pte_t *pte;
  567.  
  568.     va &= PAGE_MASK;
  569.     
  570.     dir = pgd_offset( mm, va );
  571.     if (dir)
  572.     {
  573.         pmd = pmd_offset(dir, va & PAGE_MASK);
  574.         if (pmd && pmd_present(*pmd))
  575.         {
  576.             pte = pte_offset(pmd, va);
  577.             if (pte && pte_present(*pte))
  578.             {            
  579.                 pte_uncache(*pte);
  580.                 flush_tlb_page(find_vma(mm,va),va);
  581.             }
  582.         }
  583.     }
  584.     return pte;
  585. }
  586.  
  587. /*
  588.  * Page tables may have changed.  We don't need to do anything here
  589.  * as entries are faulted into the hash table by the low-level
  590.  * data/instruction access exception handlers.
  591.  */
  592. #define update_mmu_cache(vma, addr, pte)    do { } while (0)
  593.  
  594. /*
  595.  * When flushing the tlb entry for a page, we also need to flush the
  596.  * hash table entry.  flush_hash_page is assembler (for speed) in head.S.
  597.  */
  598. extern void flush_hash_segments(unsigned low_vsid, unsigned high_vsid);
  599. extern void flush_hash_page(unsigned context, unsigned long va);
  600.  
  601.  
  602. #define SWP_TYPE(entry) (((entry) >> 1) & 0x7f)
  603. #define SWP_OFFSET(entry) ((entry) >> 8)
  604. #define SWP_ENTRY(type,offset) (((type) << 1) | ((offset) << 8))
  605.  
  606. #define module_map      vmalloc
  607. #define module_unmap    vfree
  608.  
  609. /* CONFIG_APUS */
  610. /* For virtual address to physical address conversion */
  611. extern void cache_clear(__u32 addr, int length);
  612. extern void cache_push(__u32 addr, int length);
  613. extern int mm_end_of_chunk (unsigned long addr, int len);
  614. extern unsigned long iopa(unsigned long addr);
  615. extern unsigned long mm_ptov(unsigned long addr) __attribute__ ((const));
  616.  
  617. /* Values for nocacheflag and cmode */
  618. /* These are not used by the APUS kernel_map, but prevents
  619.    compilation errors. */
  620. #define    KERNELMAP_FULL_CACHING        0
  621. #define    KERNELMAP_NOCACHE_SER        1
  622. #define    KERNELMAP_NOCACHE_NONSER    2
  623. #define    KERNELMAP_NO_COPYBACK        3
  624.  
  625. /*
  626.  * Map some physical address range into the kernel address space.
  627.  */
  628. extern unsigned long kernel_map(unsigned long paddr, unsigned long size,
  629.                 int nocacheflag, unsigned long *memavailp );
  630.  
  631. /*
  632.  * Set cache mode of (kernel space) address range. 
  633.  */
  634. extern void kernel_set_cachemode (unsigned long address, unsigned long size,
  635.                                  unsigned int cmode);
  636.  
  637. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  638. #define PageSkip(page)        (0)
  639. #define kern_addr_valid(addr)    (1)
  640.  
  641. #endif __ASSEMBLY__
  642. #endif /* _PPC_PGTABLE_H */
  643.